﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using Moonwish.Core;
using Moonwish.Foundation.BusinessComponent;
using Moonwish.Foundation.DataEntity;

namespace Moonwish.Foundation.Service
{
    /// <summary>
    /// 值对象管理服务
    /// </summary>
    [ServiceContract(Namespace = "")]
    [SilverlightFaultBehavior]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ValueObjectService
    {
        private readonly ValueObjectClassBC _valueObjectClassBC = new ValueObjectClassBC();
        private readonly ValueObjectBC _valueObjectBC = new ValueObjectBC();

        [OperationContract]
        public List<V_FDT_ValueObjectClass> QueryValueObjectClass(Request request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (request.What != "QueryValueObjectClass")
            {
                throw new ArgumentNullException("request", "请确保Request.What=QueryValueObjectClass");
            }
            return _valueObjectClassBC.Query(request);
        }

        [OperationContract]
        public void AddValueObjectClass(List<V_FDT_ValueObjectClass> data, string userId)
        {
            if (data == null || data.Count == 0)
            {
                throw new ArgumentNullException("data");
            }
            if (String.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException("userId");
            }
            _valueObjectClassBC.Add(data, userId);
        }

        [OperationContract]
        public void SaveValueObjectClass(List<V_FDT_ValueObjectClass> data, string userId)
        {
            if (data == null || data.Count == 0)
            {
                throw new ArgumentNullException("data");
            }
            if (String.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException("userId");
            }
            _valueObjectClassBC.Update(data, userId);
        }

        [OperationContract]
        public void PublishValueObjectClass(List<string > ids, string userId)
        {
            if (ids == null || ids.Count == 0)
            {
                throw new ArgumentNullException("ids");
            }
            if (String.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException("userId");
            }
            _valueObjectClassBC.Publish(ids, userId);
        }

        [OperationContract]
        public void DisableValueObjectClass(List<string > ids, string userId)
        {
            if (ids == null || ids.Count == 0)
            {
                throw new ArgumentNullException("ids");
            }
            if (String.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException("userId");
            }
            _valueObjectClassBC.Disable(ids, userId);
        }

        [OperationContract]
        public void DeleteValueObjectClass(List<string> ids, string userId)
        {
            if (ids == null || ids.Count == 0)
            {
                throw new ArgumentNullException("ids");
            }
            if (String.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException("userId");
            }
            _valueObjectClassBC.Delete(ids, userId);
        }

        [OperationContract]
        public void AddValueObject(List<V_FDT_ValueObject> data, string userId)
        {
            if (data == null || data.Count == 0)
            {
                throw new ArgumentNullException("data");
            }
            if (String.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException("userId");
            }
            _valueObjectBC.Add(data, userId);
        }

        [OperationContract]
        public void SaveValueObject(List<V_FDT_ValueObject> data, string userId)
        {
            if (data == null || data.Count == 0)
            {
                throw new ArgumentNullException("data");
            }
            if (String.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException("userId");
            }
            _valueObjectBC.Update(data, userId);
        }

        [OperationContract]
        public void PublishValueObject(List<string> ids, string userId)
        {
            if (ids == null || ids.Count == 0)
            {
                throw new ArgumentNullException("ids");
            }
            if (String.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException("userId");
            }
            _valueObjectBC.Publish(ids, userId);
        }

        [OperationContract]
        public void DisableValueObject(List<string> ids, string userId)
        {
            if (ids == null || ids.Count == 0)
            {
                throw new ArgumentNullException("ids");
            }
            if (String.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException("userId");
            }
            _valueObjectBC.Disable(ids, userId);
        }

        [OperationContract]
        public void DeleteValueObject(List<string> ids, string userId)
        {
            if (ids == null || ids.Count == 0)
            {
                throw new ArgumentNullException("ids");
            }
            if (String.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException("userId");
            }
            _valueObjectBC.Disable(ids, userId);
        }
    }
}
